import { connect } from 'react-redux'
import AdminIndexPicturesCtrl from "../../components/admin/AdminIndexPicturesCtrl/AdminIndexPicturesCtrl.jsx"
import {getCourseList,searchCourse,sortCourseList,SORT,filterCourse,changePage,selectCourse,move,addCourse,delItem} from "../../actions/admin/admin_pictures_actions.js"

const mapDispatchToProps = (dispatch) => {
    return {
        refresh : (filter) => {
            filter = filter || "ALL"
            dispatch(getCourseList())
        },
        init : () => {
            dispatch(getCourseList())
        },
        sort : (sortIdx,sortFlag) => {
            dispatch(sortCourseList(sortIdx,sortFlag))
        },
        search : (searchText) => {
            dispatch(searchCourse(searchText))
        },
        filter : (filterName) => {
            dispatch(filterCourse(filterName))
        },
        changePage : (page,limit) => {
            dispatch(changePage(page,limit))
        },
        selectCourse : (course) => {
            dispatch(selectCourse(course))
        },
        move : (direction,course) => {
            dispatch(move(direction,course))
        },
        addCourse : (course) => {
            dispatch(addCourse(course))
        },
        delItem : (item) => {
            dispatch(delItem(item))
        }
    }
}

const mapStateToProps = (state,ownProps) => {
    const {adminCourseTable} = state
    return {
        courses : adminCourseTable.courses,
        totalCount : adminCourseTable.cachedCourses.length,
        cachedCourses : adminCourseTable.cachedCourses,
        page : adminCourseTable.page,
        limit : adminCourseTable.limit,
        selectedCourses : adminCourseTable.selectedCourses
    }
}

const AdminCourseCtrlContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(AdminIndexPicturesCtrl)

export default AdminCourseCtrlContainer